home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Manage.aspx.cs669 < prev    next >
Text File  |  2008-04-09  |  31KB  |  697 lines

  1. using System;
  2. using System.Collections;
  3. using System.Data.Common;
  4. using System.IO;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using GBPVR.Public;
  9. using GBPVRSchedule;
  10. using gbweb.classes;
  11.  
  12. namespace gbweb
  13. {
  14.     /// <summary>
  15.     /// Summary description for Manage.
  16.     /// </summary>
  17.     public partial class Manage : Page
  18.     {
  19.  
  20.         private Settings guideParams;
  21.         protected ProgramTreeItem[] pgmTree;
  22.         protected int treeIdx;
  23.         private IList myScheduledRecordings;
  24.         private TableRow headerRow;
  25.         private TableCell colStatus;
  26.         private TableCell colAirDate;
  27.         private TableCell colChannel;
  28.         private TableCell colShow;
  29.         private TableRow recordingRow;
  30.         private Channel channel;
  31.  
  32.  
  33.         Hashtable channelCache = new Hashtable();
  34.  
  35.         private void checkRecordingType(ref int recordingTypeFilter, string text, int value)
  36.         {
  37.             ListItem item = recordingTypes.Items.FindByValue(value.ToString());
  38.             int flag = (int)Math.Pow(2, value);
  39.             if (item == null)
  40.             {
  41.                 item = new ListItem(text, value.ToString());
  42.                 recordingTypes.Items.Add(item);
  43.                 item.Selected = (recordingTypeFilter & flag) != 0;
  44.             }
  45.             else
  46.             {
  47.                 if (item.Selected)
  48.                     recordingTypeFilter = recordingTypeFilter | flag;
  49.                 else
  50.                     recordingTypeFilter = recordingTypeFilter & (0xffff - flag);
  51.             }
  52.         }
  53.  
  54.         protected void Page_Load(object sender, EventArgs e)
  55.         {
  56.             Session["GuideStartTime"] = null;
  57.             guideParams = Global.Settings;
  58.             treeIdx = 0;
  59.             pgmTree = new ProgramTreeItem[1000];
  60.             
  61.             HttpCookie cookie = Request.Cookies["recordingTypeFilter"];
  62.             int recordingTypeFilter = cookie != null ? Convert.ToInt32(cookie.Value) : 0xffbf;
  63.             //Check to see if the user selected the option for all filters or no filters and set the filter value accordingly
  64.             if (recordingTypes.SelectedValue == "all")
  65.             {
  66.                 recordingTypeFilter = 65535;
  67.                 //Set all the filter select boxes to true
  68.                 for (int a = 0; a < recordingTypes.Items.Count; a++)
  69.                 {
  70.                     recordingTypes.Items[a].Selected = true;
  71.                 }
  72.                 //Uncheck the All and None options
  73.                 recordingTypes.Items[0].Selected = false;
  74.                 recordingTypes.Items[1].Selected = false;
  75.             }
  76.             else if (recordingTypes.SelectedValue == "none")
  77.             {
  78.                 recordingTypeFilter = 65408;
  79.                 //Set all the filter select boxes to false
  80.                 for (int a = 0; a < recordingTypes.Items.Count; a++)
  81.                 {
  82.                     recordingTypes.Items[a].Selected = false;
  83.                 }
  84.             }
  85.             checkRecordingType(ref recordingTypeFilter, "Pending", ScheduledRecording.STATUS_PENDING);
  86.             checkRecordingType(ref recordingTypeFilter, "In Progress", ScheduledRecording.STATUS_IN_PROGRESS);
  87.             checkRecordingType(ref recordingTypeFilter, "Available", ScheduledRecording.STATUS_COMPLETED);
  88.             checkRecordingType(ref recordingTypeFilter, "Failed", ScheduledRecording.STATUS_COMPLETED_WITH_ERROR);
  89.             checkRecordingType(ref recordingTypeFilter, "Conflict", ScheduledRecording.STATUS_CONFLICT);
  90.             checkRecordingType(ref recordingTypeFilter, "Reoccurring", ScheduledRecording.STATUS_PLACE_HOLDER);
  91.             checkRecordingType(ref recordingTypeFilter, "Deleted", ScheduledRecording.STATUS_DELETED);
  92.             cookie = new HttpCookie("recordingTypeFilter", recordingTypeFilter.ToString());
  93.             cookie.Expires = DateTime.Now.AddYears(1);
  94.             Response.Cookies.Add(cookie);
  95.  
  96.             if (!IsPostBack)
  97.             {
  98.                 //Set the magic RSS links so IE and Firefox can sense the available RSS feeds
  99.                 string url = Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  100.                 try
  101.                 {
  102.                     url = url.Substring(0, url.IndexOf("/gbpvr/"));
  103.                 }
  104.                 catch
  105.                 {
  106.                     url = url.Substring(0, url.IndexOf("/gbweb/"));
  107.                 }
  108.  
  109.                 in_progressLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=in-progress");
  110.                 completedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=completed");
  111.                 pendingLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=pending");
  112.                 conflictLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=conflict");
  113.                 failedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=failed");
  114.                 seasonLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=season");
  115.                 deletedLinkH.Attributes.Add("href", url + "/gbpvr/public/rss.aspx?filter=deleted");
  116.                 
  117.                 cookie = Request.Cookies["mr_showSearchResults"];
  118.                 mr_searchResults.SelectedValue = cookie != null ? cookie.Value : "table";
  119.                 
  120.                 //If the user has opted to use the TreeView search results allow the user to see the sort order
  121.                 //options otherwise do not show them
  122.                 if (mr_searchResults.SelectedValue == "tree")
  123.                 {
  124.                     treeView.Visible = true;
  125.                     TreeView1.Visible = true;
  126.                     footer.Visible = false;
  127.                     tableView.Visible = false;
  128.                     
  129.                     //If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
  130.                     //and for original air date secondary sort
  131.                     if (ExtendedEWA.Initialize())
  132.                     {
  133.                         ListItem starRating = new ListItem();
  134.                         starRating.Text = "Star Rating";
  135.                         starRating.Value = "mr_star";
  136.                         srtOrder.Items.Add(starRating);
  137.  
  138.                         ListItem originalAirDate = new ListItem();
  139.                         originalAirDate.Text = "Original Air Date (oad)";
  140.                         originalAirDate.Value = "mr_original_date";
  141.                         srtOrder.Items.Add(originalAirDate);
  142.                     }
  143.  
  144.                     //Set the selected search order to whatever was used the last time
  145.                     cookie = Request.Cookies["mr_SortOrder"];
  146.                     srtOrder.SelectedValue = cookie != null ? cookie.Value : "mr_title";
  147.  
  148.                     cookie = Request.Cookies["mr_SecondarySortOrder"];
  149.                     sec_srtOrder.SelectedValue = cookie != null ? cookie.Value : "mrs_title";
  150.                     
  151.                 }
  152.                 else
  153.                 {
  154.                     treeView.Visible = false;
  155.                     TreeView1.Visible = false;
  156.                     footer.Visible = true;
  157.                     tableView.Visible = true;
  158.                 }
  159.             }
  160.             else
  161.             {
  162.                 if (mr_searchResults.SelectedValue == "tree")
  163.                 {
  164.                     //Store the selected sort order in the cookie for the next search
  165.                     cookie = new HttpCookie("mr_SortOrder", srtOrder.SelectedValue);
  166.                     cookie.Expires = DateTime.Now.AddYears(1);
  167.                     Response.Cookies.Add(cookie);
  168.  
  169.                     //Store the selected secondary sort order in the cookie for the next search
  170.                     cookie = new HttpCookie("mr_SecondarySortOrder", sec_srtOrder.SelectedValue);
  171.                     cookie.Expires = DateTime.Now.AddYears(1);
  172.                     Response.Cookies.Add(cookie);
  173.  
  174.                     treeView.Visible = true;
  175.                     TreeView1.Visible = true;
  176.                     footer.Visible = false;
  177.                     tableView.Visible = false;
  178.                 }
  179.                 else
  180.                 {
  181.                     treeView.Visible = false;
  182.                     TreeView1.Visible = false;
  183.                     footer.Visible = true;
  184.                     tableView.Visible = true;
  185.                 }
  186.                 
  187.                 //Store the selected display (table or tree) in the cookie for the next search
  188.                 cookie = new HttpCookie("mr_showSearchResults", mr_searchResults.SelectedValue);
  189.                 cookie.Expires = DateTime.Now.AddYears(1);
  190.                 Response.Cookies.Add(cookie);
  191.             }
  192.             
  193.             Schedule scheduleHelper = Global.Schedule;
  194.             ProgrammeDisplay displayProgramme = new ProgrammeDisplay();
  195.  
  196.             string cancel = Request.Params["cancel"];
  197.             if ((cancel != null) && (cancel.Length > 0))
  198.             {
  199.                 ScheduledRecording scheduledRecording = scheduleHelper.GetScheduledRecordingByOID(Convert.ToInt32(cancel));
  200.                 if (scheduledRecording != null)
  201.                 {
  202.                     scheduleHelper.CancelScheduledRecording(scheduledRecording);
  203.                 }
  204.             }
  205.  
  206.             if (mr_searchResults.SelectedValue != "tree")
  207.             {
  208.                 foreach (string param in Request.Params.Keys)
  209.                 {
  210.                     if (param.StartsWith("item"))
  211.                     {
  212.                         ScheduledRecording scheduledRecording =
  213.                             scheduleHelper.GetScheduledRecordingByOID(int.Parse(param.Substring(4)));
  214.                         if (scheduledRecording != null)
  215.                         {
  216.                             scheduleHelper.CancelScheduledRecording(scheduledRecording);
  217.                         }
  218.                     }
  219.                 }
  220.             }
  221.  
  222.             myScheduledRecordings = scheduleHelper.LoadRecordingSchedule();
  223.             foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
  224.             {
  225.                 int oid = scheduledRecording.getChannelOID();
  226.                 if (!channelCache.Contains(oid))
  227.                 {
  228.                     channel = scheduleHelper.GetChannelByOID(oid);
  229.                     channelCache.Add(oid, channel);
  230.                 }
  231.             }
  232.             
  233.             if (mr_searchResults.SelectedValue == "table")
  234.             {
  235.                 cookie = Request.Cookies["sortOrder"];
  236.                 string sortOrder = cookie != null ? cookie.Value.Trim(',') : "datetime,channel,title,status";
  237.                 ArrayList sortOrders = new ArrayList(sortOrder.Split(','));
  238.                 string newSort = Request["sort"];
  239.                 if (newSort != null)
  240.                 {
  241.                     if (sortOrders.Contains(newSort))
  242.                     {
  243.                         if (sortOrders[0].ToString() == newSort)
  244.                         {
  245.                             sortOrders.Remove(newSort);
  246.                             sortOrders.Insert(0, newSort + " desc");
  247.                         }
  248.                         else
  249.                         {
  250.                             sortOrders.Remove(newSort);
  251.                             sortOrders.Insert(0, newSort);
  252.                         }
  253.                     }
  254.                     else
  255.                     {
  256.                         sortOrders.Remove(newSort + " desc");
  257.                         sortOrders.Insert(0, newSort);
  258.                     }
  259.                 }
  260.                 sortOrder = string.Join(",", (string[])sortOrders.ToArray(typeof(string)));
  261.                 cookie = new HttpCookie("sortOrder", sortOrder);
  262.                 cookie.Expires = DateTime.Now.AddYears(1);
  263.                 Response.Cookies.Add(cookie);
  264.  
  265.                 // put table header
  266.                 headerRow = new TableRow();
  267.  
  268.                 //Guest Users do not get access to initiatie, delete or cancel recordings. 
  269.                 if (Convert.ToBoolean((string)Session["NotGuestUser"]))
  270.                 {
  271.                     TableCell col1 = new TableCell();
  272.                     col1.Text =
  273.                         "<input type=\"checkbox\" class=\"selectall\" onclick=\"SelectAllCheckboxes(this);\"><b>Select</b>";
  274.                     col1.Text +=
  275.                         "<a id=\"massCancel\" class=\"btn-normal-small-red\" href=\"javascript:__doPostBack('massCancel','')\"><span>Delete</span></a>";
  276.                     col1.CssClass = "header";
  277.                     col1.Width = 25;
  278.                     headerRow.Cells.Add(col1);
  279.                 }
  280.  
  281.                 colStatus = new TableCell();
  282.                 colStatus.Text = "<a href=\"?sort=status\"><b>Status</b></a>" + getSortDescription(sortOrders[0], "status");
  283.                 colStatus.CssClass = "header";
  284.                 colStatus.Width = 150;
  285.                 colStatus.Wrap = false;
  286.                 headerRow.Cells.Add(colStatus);
  287.  
  288.                 colAirDate = new TableCell();
  289.                 colAirDate.Text = "<a href=\"?sort=datetime\">Air Date</a>" + getSortDescription(sortOrders[0], "datetime");
  290.                 colAirDate.CssClass = "header";
  291.                 colAirDate.Wrap = false;
  292.                 headerRow.Cells.Add(colAirDate);
  293.  
  294.                 colChannel = new TableCell();
  295.                 colChannel.Text = "<a href=\"?sort=channel\">Channel</a>" + getSortDescription(sortOrders[0], "channel");
  296.                 colChannel.CssClass = "header";
  297.                 colChannel.Wrap = false;
  298.                 headerRow.Cells.Add(colChannel);
  299.  
  300.                 colShow = new TableCell();
  301.                 colShow.Text = "<a href=\"?sort=title\">Show</a>" + getSortDescription(sortOrders[0], "title");
  302.                 colShow.CssClass = "header";
  303.                 colShow.Wrap = false;
  304.                 colShow.Width = 350;
  305.                 headerRow.Cells.Add(colShow);
  306.  
  307.                 schedView.Rows.Add(headerRow);
  308.  
  309.                 if (myScheduledRecordings is ArrayList)
  310.                     ((ArrayList)myScheduledRecordings).Sort(new RecordingComparer(sortOrders, channelCache));
  311.             }
  312.             
  313.             bool strmAllowed = File.Exists(Path.Combine(guideParams.strmVLCLoc, "vlc.exe"));
  314.             
  315.             foreach (ScheduledRecording scheduledRecording in myScheduledRecordings)
  316.             {
  317.                 int flag = (int)Math.Pow(2, scheduledRecording.getRecordingStatus());
  318.                 if ((recordingTypeFilter & flag) == 0) continue;
  319.  
  320.                 recordingRow = new TableRow();
  321.                 recordingRow.CssClass = "manage_recordings_row";
  322.  
  323.                 TableCell detailCol1 = new TableCell();
  324.                 if (scheduledRecording != null)
  325.                 {
  326.                     detailCol1.Text = "<input name=\"item" + scheduledRecording.getOID() + "\" type=\"checkbox\" value=\"" + scheduledRecording.getOID() + "\">";
  327.                 }
  328.  
  329.                 colStatus = new TableCell();
  330.                 colStatus.VerticalAlign = VerticalAlign.Top;
  331.  
  332.                 colAirDate = new TableCell();
  333.                 colAirDate.VerticalAlign = VerticalAlign.Top;
  334.                 colAirDate.Wrap = false;
  335.  
  336.                 colChannel = new TableCell();
  337.                 colChannel.VerticalAlign = VerticalAlign.Top;
  338.  
  339.                 colShow = new TableCell();
  340.                 colShow.VerticalAlign = VerticalAlign.Top;
  341.  
  342.                 String quality;
  343.  
  344.                 switch (scheduledRecording.getQualitySetting())
  345.                 {
  346.                     case (int)Schedule.Quality.Low:
  347.                         quality = "Low";
  348.                         break;
  349.                     case (int)Schedule.Quality.Medium:
  350.                         quality = "Medium";
  351.                         break;
  352.                     case (int)Schedule.Quality.High:
  353.                         quality = "High";
  354.                         break;
  355.                     case (int)Schedule.Quality.Custom1:
  356.                         quality = "Custom 1";
  357.                         break;
  358.                     case (int)Schedule.Quality.Custom2:
  359.                         quality = "Custom 2";
  360.                         break;
  361.                     case (int)Schedule.Quality.LiveTV:
  362.                         quality = "LiveTV";
  363.                         break;
  364.                     default:
  365.                         quality = string.Empty;
  366.                         break;
  367.                 }
  368.  
  369.                 Programme programme = scheduledRecording.getProgramme();
  370.                 channel = (Channel)channelCache[scheduledRecording.getChannelOID()];
  371.  
  372.                 if (mr_searchResults.SelectedValue == "table")
  373.                 {
  374.                     switch (scheduledRecording.getRecordingStatus())
  375.                     {
  376.                         case ScheduledRecording.STATUS_PENDING:
  377.                             colStatus.CssClass = "pending";
  378.                             colStatus.Text = "<span class=\"title\">" + "Pending<br/>" +
  379.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  380.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  381.                                              "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a>";
  382.                             break;
  383.                         case ScheduledRecording.STATUS_IN_PROGRESS:
  384.                             colStatus.CssClass = "inprogress";
  385.                             colStatus.Text = "<span class=\"title\">" + "In Progress<br/>" +
  386.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  387.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  388.                                              "<a href=\"" + Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Play Program</span></a>" +
  389.                                              "<a href=\"" + Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Download</span></a>";
  390.                             if (strmAllowed)
  391.                             {
  392.                                 colStatus.Text += "<a href=\"public/Player.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" class=\"btn-normal-small\"><span>Stream</span></a>";
  393.                             }
  394.                             if (programme == null)
  395.                             {
  396.                                 colStatus.Text += "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a>";
  397.                             }
  398.                             break;
  399.                         case ScheduledRecording.STATUS_COMPLETED:
  400.                             colStatus.CssClass = "available";
  401.                             colStatus.Text = "<span class=\"title\">" + "Available<br/>" +
  402.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  403.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  404.                                              "<a href=\"" + Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Play Program</span></a>" +
  405.                                              "<a href=\"" + Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\" class=\"btn-normal-small\"><span>Download</span></a>";
  406.                             if (strmAllowed)
  407.                             {
  408.                                 colStatus.Text += "<a href=\"public/Player.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" + "\" onclick=\"EditPop5(this.href,'Add1');return false;\" class=\"btn-normal-small\"><span>Stream</span></a>";
  409.                             }
  410.                             if (programme == null)
  411.                             {
  412.                                 colStatus.Text += "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a>";
  413.                             }
  414.                             break;
  415.                         case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  416.                             colStatus.CssClass = "failed";
  417.                             colStatus.Text = "<span class=\"title\">" + "Failed<br/>" +
  418.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  419.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  420.                                              "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a>";
  421.                             break;
  422.                         case ScheduledRecording.STATUS_CONFLICT:
  423.                             colStatus.CssClass = "conflict";
  424.                             colStatus.Text = "<span class=\"title\">" + "Conflict<br/>" +
  425.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  426.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  427.                                              "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small\"><span>Delete</span></a>";
  428.                             break;
  429.                         case ScheduledRecording.STATUS_PLACE_HOLDER:
  430.                             colStatus.CssClass = "reoccurring";
  431.                             colStatus.Text = "<span class=\"title\">" + "Reoccurring<br/>" + "</span>" +
  432.                                              "<img src=\"public/t.gif\" width=\"1\" height=\"4\"/><br/>" +
  433.                                              "Quality: <i>" + quality + "</i><br>" + "</span>" +
  434.                                              "<a href=\"Manage.aspx?cancel=" + scheduledRecording.getOID() + "\" class=\"btn-normal-small-red\"><span>Cancel Recording</span></a>";
  435.                             break;
  436.                         case ScheduledRecording.STATUS_DELETED:
  437.                             colStatus.CssClass = "deleted";
  438.                             colStatus.Text = "<span class=\"title\">" + "Deleted<br/>" + "</span>";
  439.                             detailCol1.Text = string.Empty;
  440.                             break;
  441.                         default:
  442.                             colStatus.Text = "NONE!!";
  443.                             detailCol1.Text = string.Empty;
  444.                             break;
  445.                     }
  446.  
  447.                     // show air date
  448.                     string date = null;
  449.                     string time = null;
  450.                     string days = string.Empty;
  451.                     switch (scheduledRecording.getRecordingType())
  452.                     {
  453.                         case ScheduledRecording.TYPE_RECORD_ONCE:
  454.                             date = scheduledRecording.getStartTime().ToLongDateString();
  455.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  456.                             break;
  457.                         case ScheduledRecording.TYPE_RECORD_DAILY:
  458.                             date = "Daily";
  459.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  460.                             break;
  461.                         case ScheduledRecording.TYPE_RECORD_WEEK_DAYS:
  462.                             date = "Week Days";
  463.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  464.                             break;
  465.                         case ScheduledRecording.TYPE_RECORD_WEEKEND_DAYS:
  466.                             date = "Weekend Days";
  467.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  468.                             break;
  469.                         case ScheduledRecording.TYPE_RECORD_WEEKLY:
  470.                             date = "Weekly: " + scheduledRecording.getStartTime().DayOfWeek.ToString();
  471.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  472.                             break;
  473.                         case ScheduledRecording.TYPE_RECORD_SEASON:
  474.                             date = "Season";
  475.                             if (scheduledRecording.getStartTime().Year != 2001)
  476.                                 time = scheduledRecording.getStartTime().ToShortTimeString() + " - " + scheduledRecording.getEndTime().ToShortTimeString();
  477.                             if (scheduledRecording != null)
  478.                             {
  479.                                 days = scheduleHelper.getSeasonDayString(scheduledRecording);
  480.                             }
  481.                             break;
  482.                     }
  483.                     colAirDate.Text = "" + date + "<br>" + time;
  484.                     if (days != string.Empty)
  485.                     {
  486.                         colAirDate.Text += "<br>" + days;
  487.                     }
  488.  
  489.                     // show channel
  490.                     if (channel != null)
  491.                     {
  492.                         string channelName = channel.getName();
  493.                         if (channelName.StartsWith(channel.getChannelNumber().ToString())) // cosmetic stuff for my american friends
  494.                         {
  495.                             if (channelName != channel.getChannelNumber().ToString())
  496.                             {
  497.                                 channelName = channelName.Substring(channel.getChannelNumber().ToString().Length + 1);
  498.                             }
  499.                             else
  500.                             {
  501.                                 channelName = "";
  502.                             }
  503.                         }
  504.                         colChannel.Text = "<span class=\"channelnumber\"><b>" + channel.getChannelNumber() + "</b></span><br><span class=\"channelname\"><nobr>" + channelName + "</nobr></span>";
  505.                     }
  506.  
  507.                     displayProgramme.FillProgrammeDisplay(Server, colShow, programme, scheduledRecording, false);
  508.  
  509.                     colStatus.CssClass = colShow.CssClass + " " + colStatus.CssClass;
  510.                     colAirDate.CssClass = colShow.CssClass;
  511.                     colChannel.CssClass = colShow.CssClass;
  512.                     
  513.                     //Guest Users do not get access to initiatie, delete or cancel recordings. 
  514.                     if (Convert.ToBoolean((string)Session["NotGuestUser"]))
  515.                     {
  516.                         recordingRow.Cells.Add(detailCol1);
  517.                     }
  518.                     recordingRow.Cells.Add(colStatus);
  519.                     recordingRow.Cells.Add(colAirDate);
  520.                     recordingRow.Cells.Add(colChannel);
  521.                     recordingRow.Cells.Add(colShow);
  522.  
  523.                     schedView.Rows.Add(recordingRow);
  524.                 }
  525.                 else
  526.                 {
  527.                     //Create a ProgrammeTreeItem to be loaded with the correct display information for the program
  528.                     ProgramTreeItem treeItem = new ProgramTreeItem();
  529.                     displayProgramme.FillProgrammeTreeArrayItem(treeItem, Server, programme, scheduledRecording, true, channel);
  530.                     //Add the loaded ProgrammeTreeITem to the Array
  531.                     pgmTree[treeIdx] = treeItem;
  532.                     treeIdx = treeIdx + 1;
  533.                 }
  534.             }
  535.  
  536.             if (mr_searchResults.SelectedValue == "tree")
  537.             {
  538.                 //Resize the array of ProgrammeTreeItems so that is isn't hogging up space.
  539.                 Array.Resize(ref pgmTree, treeIdx);
  540.                 TreeView1.Nodes.Clear();
  541.                 //Fill the TreView Control with all the nodes in the correct format
  542.                 displayProgramme.FillProgrammeTree(TreeView1, pgmTree, srtOrder.SelectedValue, sec_srtOrder.SelectedValue);
  543.  
  544.                 displayProgramme.Dispose();
  545.             }
  546.  
  547.         }
  548.  
  549.         string getSortDescription(object selectedSort, string thisSort)
  550.         {
  551.             if (selectedSort.ToString() == thisSort)
  552.                 return " (asc)";
  553.             else if (selectedSort.ToString() == thisSort + " desc")
  554.                 return " (desc)";
  555.             else
  556.                 return string.Empty;
  557.         }
  558.  
  559.         #region Web Form Designer generated code
  560.         override protected void OnInit(EventArgs e)
  561.         {
  562.             //
  563.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  564.             //
  565.             InitializeComponent();
  566.             base.OnInit(e);
  567.         }
  568.  
  569.         /// <summary>
  570.         /// Required method for Designer support - do not modify
  571.         /// the contents of this method with the code editor.
  572.         /// </summary>
  573.         private void InitializeComponent()
  574.         {
  575.  
  576.         }
  577.         #endregion
  578.  
  579.         class RecordingComparer : IComparer
  580.         {
  581.  
  582.             IList sortKeys;
  583.             Hashtable channelCache;
  584.  
  585.             public RecordingComparer(IList SortKeys, Hashtable ChannelCache)
  586.             {
  587.                 sortKeys = SortKeys;
  588.                 channelCache = ChannelCache;
  589.             }
  590.  
  591.             IComparable getRecordingValue(object obj, string key)
  592.             {
  593.                 ScheduledRecording scheduledRecording = (ScheduledRecording)obj;
  594.                 switch (key)
  595.                 {
  596.                     case "status":
  597.                     {
  598.                         switch (scheduledRecording.getRecordingStatus())
  599.                         {
  600.                             case ScheduledRecording.STATUS_PENDING:
  601.                                 return "Pending";
  602.                             case ScheduledRecording.STATUS_IN_PROGRESS:
  603.                                 return "In Progress";
  604.                             case ScheduledRecording.STATUS_COMPLETED:
  605.                                 return "Available";
  606.                             case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  607.                                 return "Failed";
  608.                             case ScheduledRecording.STATUS_CONFLICT:
  609.                                 return "Conflict";
  610.                             case ScheduledRecording.STATUS_PLACE_HOLDER:
  611.                                 return "Reoccurring";
  612.                             case ScheduledRecording.STATUS_DELETED:
  613.                                 return "Deleted";
  614.                             default:
  615.                                 return "NONE!!";
  616.                         }
  617.                     }
  618.                     case "datetime":
  619.                     {
  620.                         switch (scheduledRecording.getRecordingType())
  621.                         {
  622.                             case ScheduledRecording.TYPE_RECORD_ONCE:
  623.                                 return scheduledRecording.getStartTime().Ticks;
  624.                             default:
  625.                                 return scheduledRecording.getStartTime().TimeOfDay.Ticks;
  626.                         }
  627.                     }
  628.                     case "channel":
  629.                     {
  630.                         Channel channel = (Channel)channelCache[scheduledRecording.getChannelOID()];
  631.                         if (channel != null)
  632.                         {
  633.                             return channel.getChannelNumber();
  634.                         }
  635.                         return 0;
  636.                     }
  637.                     case "title":
  638.                     {
  639.                         Programme programme = scheduledRecording.getProgramme();
  640.                         switch (scheduledRecording.getRecordingType())
  641.                         {
  642.                             case ScheduledRecording.TYPE_RECORD_ONCE:
  643.                                 if (programme == null)
  644.                                 {
  645.                                     return "Manual Recording";
  646.  
  647.                                 }
  648.                                 else
  649.                                 {
  650.                                     if (programme.getSubTitle().Length > 0)
  651.                                     {
  652.                                         return programme.getTitle() + ": " + programme.getSubTitle();
  653.                                     }
  654.                                     else
  655.                                     {
  656.                                         return programme.getTitle();
  657.                                     }
  658.                                 }
  659.                             default:
  660.                                 return scheduledRecording.getFileName();
  661.                         }
  662.                     }
  663.                     default:
  664.                         return string.Empty;
  665.                 }
  666.             }
  667.  
  668.             #region IComparer Members
  669.  
  670.             public int Compare(object x, object y)
  671.             {
  672.                 for (int i = 0; i < sortKeys.Count; i++)
  673.                 {
  674.                     string key = sortKeys[i].ToString();
  675.                     int order = 1;
  676.                     if (key.EndsWith(" desc"))
  677.                     {
  678.                         key = key.Substring(0, key.Length - 5);
  679.                         order = -1;
  680.                     }
  681.                     int result = getRecordingValue(x, key).CompareTo(getRecordingValue(y, key));
  682.                     if (result != 0) return result * order;
  683.                 }
  684.                 return 0;
  685.             }
  686.  
  687.             #endregion
  688.  
  689.         }
  690.  
  691.         //protected void LinkButton1_Click(object sender, EventArgs e)
  692.         //{
  693.         //    return;
  694.         //}
  695. }
  696. }
  697.